#!/usr/bin/env bash

# check docker image for packaging 
if [ $# == 0 ]; then
  echo "Build Docker image as appnet-srv:4.1"
  docker image build --rm --network host --compress -t appnet-srv:4.1 -f ./Dockerfile.pkg .
fi

if [ "$(docker images -q appnet-srv:4.1 2> /dev/null)" == "" ]; then
  echo "Build Docker image as appnet-srv:4.1"
  docker image build --rm --network host --compress -t appnet-srv:4.1 -f ./Dockerfile.pkg .
fi
 
# execute commands 
if [ $# -ne 0 ]; then
  echo "$@ ..."
  docker run -v `pwd`:`pwd` -w `pwd` -i -t --rm --network host appnet-srv:4.1 $@
else
  echo "Start services ..."
  docker run --tmpfs /appins/httpp/certs-tmp -d --restart=on-failure --network host appnet-srv:4.1
fi
